package com.tedu.openmedical.statistics.controller;

import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.statistics.pojo.dto.SelectDate;
import com.tedu.openmedical.statistics.pojo.vo.PieReport;
import com.tedu.openmedical.statistics.pojo.vo.ReportChartsDate;
import com.tedu.openmedical.statistics.service.RecordCopyStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/recordCopyStatistics")
@Slf4j
public class RecordCopyStatisticsController {
    @Autowired
    RecordCopyStatisticsService recordCopyStatisticsService;

    @GetMapping("/selectByDate")
    public JsonResult selectByDate() {
        Date todayDate=new Date();//查询时间
        List<Integer> a=recordCopyStatisticsService.selectCopy(todayDate);
        log.debug("aaa");
        return JsonResult.ok(a);
    }
    @PostMapping("/selectDateByCharts")
    public JsonResult selectDateByCharts(@RequestBody SelectDate selectDate) throws ParseException {
        log.debug("前端传参，查询时间"+selectDate.toString());
       ReportChartsDate reportCharts= recordCopyStatisticsService.selectChartsData(selectDate);
        log.debug("后端返回数据"+reportCharts.toString());
        return JsonResult.ok(reportCharts);
    }

    @PostMapping("/selectDateByBarCharts")
    public JsonResult selectDateByBarCharts(@RequestBody SelectDate selectDate)
    {
        log.debug("Controller接受前端传入参数"+selectDate.toString());

        ReportChartsDate reportChartsDate=recordCopyStatisticsService.selectBarChartsData(selectDate);

        log.debug("Controller结束后传给后端的值"+reportChartsDate.toString());
        return JsonResult.ok(reportChartsDate);
    }

    @PostMapping("/selectDateByPieCharts")
    public JsonResult selectDateByPieCharts(@RequestBody SelectDate selectDate)
    {
        log.debug("Controller接受前端传入参数"+selectDate.toString());

        PieReport[] reportChartsDate=recordCopyStatisticsService.selectPieChartsData(selectDate);

        log.debug("Controller结束后传给后端的值"+reportChartsDate.toString());
        return  JsonResult.ok( reportChartsDate);
    }
    }
